package com.markus.code.exam.sanliu0;

import java.util.Scanner;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/11 21:49
 * todo:
 */
public class Main2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int n = scanner.nextInt();
            int m = scanner.nextInt();
            int a[] = new int[n + 10];
            int b[] = new int[n + 10];
            boolean bl[] = new boolean[n + 10];
            boolean work[] = new boolean[n + 10];
            boolean home[] = new boolean[n + 10];
            for (int i = 1; i <= m; i++) {
                a[i] = scanner.nextInt();
                b[i] = scanner.nextInt();
                if (b[i] == 1) {
                    work[a[i]] = true;
                } else {
                    home[a[i]] = true;
                }
            }
            for (int i = 2; i <= m - 1; i++) {
                bl[a[i]] = true;
            }
            if (b[1] == 1) {
                for (int i = 2; i <= m; i++) {
                    if (!work[a[i]] && home[a[i]]) {
                        bl[a[1]] = true;
                        break;
                    }
                }
            } else {
                if (m > 1) {
                    bl[a[1]] = true;
                }
            }
            if (b[m] == 0) {
                for (int i = m - 1; i >= 1; i--) {
                    if (work[a[i]] && !home[a[i]]) {
                        bl[m] = true;
                        break;
                    }
                }
            } else {
                if (m > 1) {
                    bl[a[m]] = true;
                }
            }
            for (int i = 1; i <= n; i++) {
                if (!bl[i]) {
                    System.out.print(i + " ");
                }
            }
        }
    }
}
